﻿Imports DTO
Imports System.Data.OleDb
Public Class CChiTietLopDAO

    Public Function ThemChiTietLop(ByVal _CTLdto As CChiTietLopDTO) As Integer
        Dim cnn As OleDbConnection = CDaTaProviderDAO.ConnectDB()
        cnn.Open()
        Dim _strinsert As String = "insert into CHITIETLOP(MaLop,MaHocSinh) values('" + _CTLdto.MaLop.ToString() + "','" + _CTLdto.MaHocSinh.ToString() + "')"
        Dim cmd As New OleDbCommand(_strinsert, cnn)
        Dim _kt As Integer = cmd.ExecuteNonQuery()
        cnn.Close()
        Return _kt
    End Function

    Public Function CapNhatChiTietLop(ByVal _HScrt1 As CHocSinhCRT1) As Integer
        Dim cnn As OleDbConnection = CDaTaProviderDAO.ConnectDB()
        cnn.Open()
        Dim _strcapnhatchitietlop = "update CHITIETLOP set MaLop=" + _HScrt1.MaLop.ToString() + " where MaHocSinh=" + _HScrt1.MaHS.ToString() + ""
        Dim _cmd As New OleDbCommand(_strcapnhatchitietlop, cnn)
        Dim _kt = _cmd.ExecuteNonQuery()
        cnn.Close()
        Return _kt
    End Function

    Public Function LaySiSocbb(ByVal _lopdto As CLopDTO) As List(Of CChiTietLopCRT)
        Dim cnn As OleDbConnection = CDaTaProviderDAO.ConnectDB()
        cnn.Open()
        Dim _strds = "select MaLop,count(MaLop) from CHITIETLOP where MaLop=" + _lopdto.MaLop.ToString() + " group by MaLop"
        Dim _cmd As New OleDbCommand(_strds, cnn)
        Dim _reader As OleDbDataReader = _cmd.ExecuteReader()
        Dim _ds As New List(Of CChiTietLopCRT)
        While _reader.Read()
            Dim _CTLcrt As New CChiTietLopCRT()
            _CTLcrt.MaLopcbb = _reader.GetInt32(0)
            _CTLcrt.SiSo = _reader.GetInt32(1)
            _ds.Add(_CTLcrt)
        End While
        cnn.Close()
        Return _ds
    End Function
End Class
